package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.*;
import cn.wolfcode.luowowo.service.*;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("destinations")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private ITravelService travelService;

    @GetMapping("/hotRegion")
    public Object hotRegion(){

        List<Region> regions = regionService.findByIshotOrderBySequenceAsc(Region.STATE_HOT);

        return JsonResult.success(regions);
    }

    @GetMapping("/search")
    public Object search(String regionId){

        List<Destination> destinations =  destinationService.search(regionId);

        return JsonResult.success(destinations);
    }

    @GetMapping("/toasts")
    public Object toasts(String destId){
        ArrayList<Destination> list = new ArrayList<>();
        List<Destination> destinations = destinationService.getToastsInfo(list, destId);
        return JsonResult.success(destinations);
    }

    @GetMapping("/catalogs")
    public Object catalogs(String destId){
        List<StrategyCatalog> strategyCatalogs =  strategyCatalogService.findByDestId(destId);
        return JsonResult.success(strategyCatalogs);
    }

    @GetMapping("/strategies/viewnumTop3")
    public Object viewnumTop3(String destId){
        List<Strategy> strategies = strategyService.findByDestIdOrderByDesc(destId);
        return JsonResult.success(strategies);
    }

    @GetMapping("/detail")
    public Object detail(String id){
        Destination destination = destinationService.get(id);
        return JsonResult.success(destination);
    }

    @GetMapping("/travels/viewnumTop3")
    public Object travelsViewnumTop3(String destId){
        List<Travel> travels = travelService.findByDestIdOrderByDesc(destId);
        return JsonResult.success(travels);
    }



}
